using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_City
	{
		private static Shop_City _instance = null;
		private Conn conn;
		public static Shop_City instance
		{
			get
			{
				if (Shop_City._instance == null)
				{
					Shop_City._instance = new Shop_City(new Conn());
				}
				return Shop_City._instance;
			}
		}
		public Shop_City()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_City(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetAllCity()
		{
			return this.conn.GetDataTable("SELECT Distinct * FROM HLShop_CityArea Order By ID Desc");
		}
		public DataTable GetCity(string Province)
		{
			DataTable result = new DataTable();
			if (Province == null || Province == "" || Province == "所有")
			{
				result = this.GetAllCity();
			}
			else
			{
				result = this.GetCityByProvince(Province);
			}
			return result;
		}
		public DataTable GetCityByWhere(string Province, string City, int Flag)
		{
			string text = "SELECT * FROM HLShop_CityArea WHERE ";
			if (Province != "")
			{
				text = text + " (Province = '" + Province + "')";
			}
			if (City != "")
			{
				text = text + " AND (City = '" + City + "')";
			}
			if (Flag == 1 || Flag == 0)
			{
				if (Province == "")
				{
					object obj = text;
					text = string.Concat(new object[]
					{
						obj,
						" (Flag = ",
						Flag,
						")"
					});
				}
				else
				{
					object obj = text;
					text = string.Concat(new object[]
					{
						obj,
						" AND (Flag = ",
						Flag,
						")"
					});
				}
			}
			text += " Order By ID Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetCityByID(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ID", DbType.Int32, ID);
			return this.conn.GetDataTable("SELECT * FROM HLShop_CityArea WHERE (ID = @ID)", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetCityByProvince(string Province)
		{
			string text = "SELECT Distinct(City),Flag FROM HLShop_CityArea ";
			if (Province != "")
			{
				text = text + " WHERE (Province = '" + Province + "') ";
			}
			text += " Order By Flag Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetCityListByProvince(string Province)
		{
			string text = "SELECT Distinct(City),Flag,ID,Province,Area,Town FROM HLShop_CityArea ";
			if (Province != "")
			{
				text = text + " WHERE (Province = '" + Province + "') ";
			}
			text += " Order By Flag Desc";
			return this.conn.GetDataTable(text);
		}
		public bool AddCity(string Province, string City, string Area, string Town, bool Flag)
		{
			bool result;
			if (!string.IsNullOrEmpty(Province) && !string.IsNullOrEmpty(City))
			{
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@Province", DbType.AnsiString, Province),
					this.conn.CreateParameter("@City", DbType.AnsiString, City),
					this.conn.CreateParameter("@Area", DbType.AnsiString, Area),
					this.conn.CreateParameter("@Town", DbType.AnsiString, Town),
					this.conn.CreateParameter("@Flag", DbType.Boolean, Flag)
				};
				result = (this.conn.Execute("INSERT INTO [HLShop_CityArea] ([Province], [City],Area ,Town ,[Flag]) VALUES (@Province, @City,@Area ,@Town, @Flag)", parameters) >= 1);
			}
			else
			{
				result = false;
			}
			return result;
		}
		public bool UpdateCity(string Province, string City, string Area, string Town, bool Flag, int ID)
		{
			bool result;
			if (!string.IsNullOrEmpty(Province) && !string.IsNullOrEmpty(City))
			{
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@Province", DbType.AnsiString, Province),
					this.conn.CreateParameter("@City", DbType.AnsiString, City),
					this.conn.CreateParameter("@Area", DbType.AnsiString, Area),
					this.conn.CreateParameter("@Town", DbType.AnsiString, Town),
					this.conn.CreateParameter("@Flag", DbType.Boolean, Flag),
					this.conn.CreateParameter("@Original_ID", DbType.Int32, ID)
				};
				result = (this.conn.Execute("UPDATE [HLShop_CityArea] SET [Province] = @Province, [City] = @City,[Area]=@Area ,[Town]=@Town ,[Flag] = @Flag WHERE (([ID] = @Original_ID))", parameters) >= 1);
			}
			else
			{
				result = false;
			}
			return result;
		}
		public bool DeleteCity(int ID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ID", DbType.Int32, ID);
			return this.conn.Execute("DELETE FROM HLShop_CityArea WHERE (ID = @ID)", new IDbDataParameter[]
			{
				dbDataParameter
			}) > 0;
		}
		public DataTable GetImportantCityByFlag(int Flag)
		{
			return this.conn.GetDataTable("SELECT * FROM HLShop_CityArea WHERE (Flag = " + Flag + ")");
		}
		public DataTable GetImportantCityByFlag()
		{
			return this.conn.GetDataTable("SELECT City, Flag, ID, Province FROM HLShop_CityArea WHERE (Flag = 1)");
		}
		public DataTable GetAllProvince()
		{
			return this.conn.GetDataTable("SELECT Distinct(Province) From [HLShop_CityArea] ");
		}
		public DataTable GetAllAreaByCity(string city)
		{
			return this.conn.GetDataTable("select distinct(Area),Flag from dbo.HLShop_CityArea where City='" + city + "'  order by Flag Desc");
		}
		public DataTable GetAreaByCityFromHLShop_CityAreaArea(string City)
		{
			string text = "select Distinct(Area) from HLShop_CityArea ";
			if (City != "")
			{
				text = text + " WHERE (City = '" + City + "')  and Area  is not  null ";
			}
			text += " Order By Area Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAllProvinceHL_City()
		{
			return this.conn.GetDataTable("SELECT Distinct(Province) From [HL_City] order by Province asc");
		}
		public DataTable GetCityByProvinceFromHL_CityAreaCity(string Province)
		{
			string text = "SELECT Distinct(City) FROM HL_City ";
			if (Province != "")
			{
				text = text + " WHERE (Province = '" + Province + "') and City  is not  null  and City<>' '";
			}
			text += " Order By City Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetDropDownCityByProvince(string Province)
		{
			string text = "SELECT Distinct(City) FieldValue FROM HL_City ";
			if (Province != "")
			{
				text = text + " WHERE (Province = '" + Province + "') and City  is not  null  and City<>' '";
			}
			text += " Order By City Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetDropDownAreaByCity(string City)
		{
			string text = "select Distinct(Area) FieldValue from HL_City ";
			if (City != "")
			{
				text = text + " WHERE (City = '" + City + "')  and Area  is not  null  and Area<>''";
			}
			text += " Order By Area Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAreaByCityFromHL_CityAreaArea(string City)
		{
			string text = "select Distinct(Area) from HL_City ";
			if (City != "")
			{
				text = text + " WHERE (City = '" + City + "')  and Area  is not  null  and Area<>''";
			}
			text += " Order By Area Desc";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetCityByArea(string area)
		{
			string sql = "Select * from HL_City Where Area='" + area + "'";
			return this.conn.GetDataTable(sql);
		}
	}
}
